<?php
/**
 * Created by PhpStorm.
 * User: liuhong
 * Date: 2019-04-10
 * Time: 11:25
 */

namespace app\service;

use app\api\controller\Pay;
use app\common\model\MoneyLog as MoneyLogModel;
use think\Db;
use think\Exception;

/**佣金以及充值币
 * Class MoneylogService
 * @package app\service
 */
class MoneylogService extends BaseService
{
    public $moneyLogModel;
    public function __construct()
    {
        $this->moneyLogModel = new MoneyLogModel();
    }

    /**新增
     * @param $add
     * @return int|string
     */
    public function addAll($add){
       return $this->moneyLogModel->insertAll($add);
    }

    /**新增
     * @param $add
     * @return int|string
     */
    public function add($add){
        return $this->moneyLogModel->insertGetId($add);
    }


    /**
     * 查询列表
     * @param $where
     * @param $page
     * @param int $page_num
     * @return array|bool
     */
    public function selectList($where,$page=1,$page_num=20){
        try{
            return $this->moneyLogModel
                ->where($where)
                ->order('id desc')
                ->page($page,$page_num)
                ->select()
                ->toArray();
        }catch (Exception $ex){
            LogService::S()->writeLog('Exception',$ex->getMessage());
            return false;
        }
    }


    /**
     * 查询总数
     * @param $where
     * @return bool|int|string
     */
    public function countList($where){
        try{
           return $this->moneyLogModel->where($where)->count();
        }catch (Exception $ex){
           return false;
        }
    }


    //
    public function backMoney($order_id){

    }


    //查询单个日志
    public function find_log($id){
        try{
            $re=$this->moneyLogModel->where("id",$id)->find();
            if($re){
                return $re->toArray();
            }else{
                return false;
            }
        }catch (Exception $ex){
            return false;
        }
    }
}